package cn.zymall.seckill.controller;

import cn.zymall.common.model.SeckillSku;
import cn.zymall.common.model.SeckillSpu;
import cn.zymall.common.utils.response.HttpResult;
import cn.zymall.seckill.service.SecKillService;
import cn.zymall.seckill.service.SecKillSpuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author xuxianda
 * @Description: 秒杀主业务商品控制层
 * @date 2020/8/23 21:00
 * @Copyright
 * @return
 **/
@RestController
@RequestMapping("/cache")
public class SecKillSpuController {

    @Autowired
    SecKillService secKillService;

    @GetMapping
    public HttpResult<SeckillSpu> get(String secKillSpuId) {
        if (secKillSpuId == null || secKillSpuId.equals("")) {
            return new HttpResult().fail("secKillSpuId不能为空");
        }
        return secKillService.getSecKillSpu(secKillSpuId);
    }

    /**
     * 将抢购商品写入缓存    ---测试使用  生成环境注释掉该方法
     *
     * @param spu
     * @return
     */
    @PostMapping("/spu")
    public HttpResult add(@RequestBody SeckillSpu spu) {
        return secKillService.addSecKillSpu(spu);
    }

    /**
     * 将抢购商品的规格信息写入缓存    ---测试使用  生成环境注释掉该方法
     *
     * @param sku
     * @return
     */

    @PostMapping("sku")
    public HttpResult addSku(@RequestBody SeckillSku sku) {
        return secKillService.addSecKillSku(sku);
    }

}
